<template>
	<view class="index_activity">
		<!-- banner -->
		<view class="banner">
			<view class="banner_txt">
				公告
			</view>
			<swiper class="swiper_list" :disable-touch="true" :autoplay="true" :circular="true" :vertical="true"
				:duration="600" :interval="2500">
				<swiper-item class="swiper_item" v-for="item,index in bannerArr" :key="index">
					<view class="container">
						<view class="nickname">
							{{item.nickname}}
						</view>
						<view class="activity">
							刚刚参加了活动
						</view>
						<view class="name">
							{{item.name}}
						</view>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<!-- 活动 -->
		<compActivity :hotArr="ongoing" :endArr="ended"></compActivity>
		<!-- loading -->
		<compLoad :state="status"></compLoad>
		<view id="touch_bottom"></view>
	</view>
</template>

<script>
	import compLoad from '../compLoad/compLoad.vue'
	import compActivity from '../compActivity/compActivity.vue'
	export default {
		name: "indexActivity",
		data() {
			return {
				bannerArr: null,
				ended: null,
				ongoing: null,
				status: true,
				page: 0
			};
		},
		components: {
			compActivity,
			compLoad
		},
		mounted() {
			let io = new IntersectionObserver(this.touchList, {});
			let viewList = document.getElementById('touch_bottom');
			io.observe(viewList);
		},
		created() {
			this.getData(0)
		},
		methods: {
			getData(k) {
				this.status = true
				this.$axios('home/events/getlists', {
					params: {
						offset: k,
						limit: 20
					}

				}).then(res => {
					console.log('活动数据---->', res);
					if (k == 0) {
						this.bannerArr = res.banner;
						this.ended = res.ended.events;
						this.ongoing = res.ongoing.events;
						this.status = false;
					} else {
						this.ended = this.ended.concat(res.ended.events);
						this.status = false;
					}
				})
			},
			touchList(k) {
				if (this.status == false) {
					k = k[0];
					let isShow = k.isIntersecting;
					if (isShow) {
						let tempIndex = ++ this.page;
						console.log('this.page ++', tempIndex);
						this.getData(tempIndex)
					}
				}

			}
		}
	}
</script>

<style lang="scss">
	.index_activity {
		width: 100%;
		margin-top: 190rpx;

		.banner {
			width: 90%;
			height: 60rpx;
			background-color: rgb(240, 240, 240);
			margin: 0 auto;

			border-radius: 14rpx;
			display: flex;
			align-items: center;

			.banner_txt {
				font-size: 20rpx;
				padding: 2rpx 4rpx;
				width: 60rpx;
				height: 30rpx;
				line-height: 30rpx;
				font-weight: bold;
				margin-left: 10rpx;
				border-bottom-left-radius: 10rpx;
				border-top-right-radius: 10rpx;
				// border-radius: 10rpx;
				// line-height: 80rpx;
				background-color: #FECD4A;
			}

			.swiper_list {
				width: 100%;
				height: 100%;

				.swiper_item {
					width: 100%;
					height: 100%;

					.container {
						width: 100%;
						height: 100%;
						margin-left: 10rpx;
						display: flex;
						align-items: center;
						font-size: 20rpx;

						.nickname {
							width: 18%;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
							font-weight: bold;
						}

						.activity {
							width: 30%;
						}

						.name {
							width: 46%;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
							font-weight: bold;
						}
					}

				}
			}
		}
	}
</style>
